package com.hm.hall.user.service;

import com.hm.hall.commons.dao.UserLoginLogMapper;
import com.hm.hall.commons.domain.User;
import com.hm.hall.commons.domain.UserLoginLog;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * 用户登录日志
 */
@Service
public class UserLoginLogService {

    @Autowired
    private UserLoginLogMapper userLoginLogMapper;

    @Async
    public void insertUserLoginLog(User user, String ipAddr, String headerUserAgent, String remark) {
        UserLoginLog loginLog = new UserLoginLog();
        loginLog.setUserId(user.getUserId());
        //loginLog.setGameChannelKey(user.getGameChannelKey());
        loginLog.setAddr(ipAddr);
        loginLog.setLocation(user.getCountry() + " " + user.getCity()); // 所在地
        loginLog.setCreateTime(new Date());
        loginLog.setHeaderUserAgent(headerUserAgent);
        loginLog.setRemark(remark);
        userLoginLogMapper.insertSelective(loginLog);
    }


}



